<!-- @Author: Yu_Bo -->
<template>
	<view class="wo" :style="[pageStyle]">
		<!-- nav -->
		<c-navbar navtype='wo'></c-navbar>
		<!-- background -->
		<view class="page_background"></view>
		<!-- main -->
		<view class="wo_main">
			<!-- info -->
			<view class="main_info" @click="loginBtn">
				<view class="info_avatar">
					<image v-if="userinfo" :src="userinfo.avatar" mode="aspectFill"></image>
					<image v-else src="@/static/images/img/logo.png" mode="aspectFill"></image>
				</view>
				<view class="info_name" v-if="userinfo">
					<view class="name">
						{{userinfo.nickname}}
					</view>
					<view class="txt">
						ID：{{userinfo.id}}
					</view>
				</view>
				<view class="info_name" v-else>
					<view class="name">
						登录/注册
					</view>
					<view class="txt">
						点击登录 享受更多精彩信息
					</view>
				</view>
				<view class="info_right" v-if="admin == 1" @click.stop="warehouseBtn">
					库管功能
				</view>
			</view>
			<!-- money -->
			<view class="main_money">
				<view class="money_info">
					<image src="@/static/images/img/wo_money_background.png" mode=""></image>
					<view class="info_txt">
						<view class="txt_left">
							<view class="left_title">
								我的钱包
							</view>
							<view class="left_num">
								{{userinfo?userinfo.money : "--"}}
							</view>
						</view>
						<view class="txt_right" @click="moneyBtn">
							查看
						</view>
					</view>
				</view>
			</view>
			<!-- order -->
			<view class="main_order">
				<view class="order_title">
					我的订单
				</view>
				<view class="order_list">
					<view class="list_txt" v-for="(item, index) in orderData" :key="index" @click="orderBtn(item)">
						<image :src="item.icon" mode=""></image>
						<view class="txt">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
			<!-- tool -->
			<view class="main_order">
				<view class="order_title">
					我的工具
				</view>
				<view class="order_list">
					<view class="list_txt" v-for="(item, index) in toolData" :key="index" @click="toolBtn(item)">
						<image :src="item.icon" mode=""></image>
						<view class="txt">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
			<!-- inv -->
			<view class="main_inv" @click="invBtn">
				<image src="@/static/images/img/wo_inv_img.png" mode=""></image>
			</view>
		</view>
		<!--  -->
		<c-warehouse ref="warehouse"></c-warehouse>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		components: {},
		data() {
			return {
				// 我的订单
				orderData: [
					{
						icon: require('@/static/images/img/wo_order_icon1.png'),
						name: "买书订单",
						path: "/pagesWo/buying/index",
					},
					{
						icon: require('@/static/images/img/wo_order_icon2.png'),
						name: "卖书订单",
						path: "/pagesWo/selling/index",
					},
					{
						icon: require('@/static/images/img/wo_order_icon3.png'),
						name: "快递订单",
						path: "/pagesWo/express/index",
					}
				],
				// 我的工具
				toolData: [
					{
						icon: require('@/static/images/img/wo_tool_icon1.png'),
						name: "我的地址",
						path: "/pagesWo/address/index",
					},
					{
						icon: require('@/static/images/img/wo_tool_icon2.png'),
						name: "客服中心",
						path: "/pagesWo/service/index",
					},
					{
						icon: require('@/static/images/img/wo_tool_icon3.png'),
						name: "应用设置",
						path: "/pagesWo/setup/index",
					}
				]
			}
		},
		computed: {
			...mapState({
				admin: (state) => state.admin,
				userinfo: (state) => state.userinfo
			}),
			pageStyle() {
				return {
					'--pagebackground': "url(" + require('@/static/images/img/wo_nav_bg.png') + ")"
				}
			}
		},
		onLoad() {},
		onShow() {
			if(this.$store.state.token) {
				this.$store.dispatch('getUserInfo')
			}
		},
		methods: {
			// 查看
			moneyBtn() {
				this.$navToLogin("/pagesWo/money/index")
			},
			// 订单
			orderBtn(item) {
				this.$navToLogin(item.path)
			},
			// 工具
			toolBtn(item) {
				this.$navToLogin(item.path)
			},
			// 分享返现
			invBtn() {
				this.$navToLogin("/pagesWo/share/index")
			},
			// 登录
			loginBtn() {
				if(this.userinfo.id) return
				uni.showLoading({
					title: "登录中..."
				})
				this.$getLogin()
			},
			// 库管
			warehouseBtn() {
				this.$refs.warehouse.openBtn()
			},
		},
	}
</script>

<style lang='scss' scoped>
	.wo {
		width: 100%;

		.wo_main {
			position: relative;
			z-index: 2;
			width: 100%;
			padding: 50rpx 0 0;

			.main_info {
				position: relative;
				width: 100%;
				height: 120rpx;
				padding: 0 30rpx;
				display: flex;
				align-items: center;

				.info_avatar {
					width: 120rpx;
					height: 120rpx;

					image {
						display: block;
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}

				.info_name {
					padding-left: 30rpx;
					color: #ffffff;

					.name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 36rpx;
					}

					.txt {
						padding-top: 5rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
					}
				}

				.info_right {
					position: absolute;
					right: 0;
					top: 30rpx;
					z-index: 1;
					width: 165rpx;
					height: 60rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #222222;
					background: linear-gradient(90deg, #F2CFFF 0%, #94F8FF 100%);
					border-radius: 30rpx 0 0 30rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.main_money {
				width: 100%;
				padding: 0 30rpx;
				margin-top: 60rpx;

				.money_info {
					position: relative;
					width: 100%;
					height: 168rpx;

					image {
						position: absolute;
						top: 0;
						left: 0;
						z-index: 1;
						display: block;
						width: 100%;
						height: 100%;
					}

					.info_txt {
						position: relative;
						z-index: 2;
						width: 100%;
						height: 100%;
						padding: 0 30rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.txt_left {
							color: #222222;

							.left_title {
								font-family: PingFang SC, PingFang SC;
								font-weight: 400;
								font-size: 28rpx;
							}

							.left_num {
								padding-top: 10rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 600;
								font-size: 40rpx;
							}
						}

						.txt_right {
							width: 152rpx;
							height: 60rpx;
							line-height: 56rpx;
							text-align: center;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 26rpx;
							color: #FFFFFF;
							background: linear-gradient(90deg, #B554FF 0%, #6357FF 100%);
							border-radius: 30rpx;
							border: 2rpx solid rgba(255, 255, 255, 0.51);
						}
					}
				}
			}
			
			.main_order {
				width: 690rpx;
				padding-bottom: 40rpx;
				margin: 30rpx auto 0;
				background: #FFFFFF;
				border-radius: 30rpx;
				box-shadow: 0rpx 6rpx 20rpx 2rpx rgba(153,153,153,0.15);
				
				.order_title {
					width: 100%;
					padding: 30rpx 30rpx 40rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 32rpx;
					color: #222222;
				}
				
				.order_list {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.list_txt {
						width: 33.33%;
						
						image {
							display: block;
							width: 70rpx;
							height: 70rpx;
							margin: auto;
						}
						
						.txt {
							width: 100%;
							text-align: center;
							padding-top: 20rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 28rpx;
							color: #222222;
						}
					}
				}
			}
			
			.main_inv {
				width: 100%;
				height: 260rpx;
				padding: 30rpx;
				
				image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>